<?php
!defined( 'IN_HDWIKI' ) && exit( 'Access Denied' );

class qqmodel
{
	var $db;
	var $base;

	function qqmodel( & $base )
	{
		$this->base = $base;
		$this->db = $base->db;
	}

	function update_oauth_keys( $keys )
	{
		$this->db->update_field( 'socialconnect', 'qq_oauth_token', $keys['oauth_token'], "qq_user_name = '".$keys['name']."'" );
		$this->db->update_field( 'socialconnect', 'qq_oauth_token_secret', $keys['oauth_token_secret'], "qq_user_name = '".$keys['name']."'" );
	}

	function bind( $uid, $keys )
	{
		if ( $this->db->fetch_by_field( 'socialconnect', 'uid', $uid ) ) {
			$this->db->update_field( 'socialconnect', 'qq_user_name', $keys['name'], "uid = {$uid}" );
			$this->db->update_field( 'socialconnect', 'qq_oauth_token', $keys['oauth_token'], "uid = {$uid}" );
			$this->db->update_field( 'socialconnect', 'qq_oauth_token_secret', $keys['oauth_token_secret'], "uid = {$uid}" );
		} else {
			$sql = "INSERT INTO ".DB_TABLEPRE."socialconnect( uid, qq_user_name, qq_oauth_token, qq_oauth_token_secret ) VALUES( {$uid}, '".$keys['name']."', '".$keys['oauth_token']."', '".$keys['oauth_token_secret']."' );";
			$this->db->query( $sql );
		}
	}

	function unbind( $uid )
	{
		if ( $this->db->fetch_by_field( 'socialconnect', 'uid', $uid ) ) {
			$this->db->update_field( 'socialconnect', 'qq_user_name', NULL, "uid = {$uid}" );
			$this->db->update_field( 'socialconnect', 'qq_oauth_token', NULL, "uid = {$uid}" );
			$this->db->update_field( 'socialconnect', 'qq_oauth_token_secret', NULL, "uid = {$uid}" );
			$this->db->update_field( 'socialconnect', 'qq_setting', NULL, "uid = {$uid}" );
		}
	}
}
?>
